<?php
include ('cruceros.php');


class filtros_check_cruceros extends filtros_cruceros{
	
	public $filters_type				= 'check';
	public $filtros_adicionales 		= array();
	public $filtros_obligatorios		= array( 'ocupantes'=>'','region'=>'' );
	public $url_den						= 'cruceros/resultados';
	
	function __construct($url,$region_id,$currency='$'){
	
		$this->init_aditional_filters($url);
		$this->region_id = $this->filtros_obligatorios['region'];
		
		foreach ($this->filters_list as $key => $filter){
			$this->filters_list[$key]['selected_value'] = array();
		}
		
		parent::__construct($url,$currency);
		
	}
	
	function get_display_text($denomination,$value){
		global $db;
		$return_string = $denomination;
		return $return_string;
	}
	
	function get_parameters($string){
		$exploded_string = explode('/',$string);
		$return = array();
		foreach ($this->filters_list as $currentKey => $currentFilter){
			if ($currentFilter['filter_type'] == 'items_list' ){
				if (in_array($currentFilter['field_denomination'],$exploded_string)){
					$pos 			= array_search($currentFilter['field_denomination'],$exploded_string);
					$values_array 	= explode('-',$exploded_string[$pos+1]);
					for($i=0;$i<count($values_array);$i++){
						$values_array[$i] = str_replace('+',' ',$values_array[$i]);
					}
					$return[$currentFilter['field_denomination']] = $values_array;
				}
			}
		}
		return $return;
	}
	
	function get_filter_url($base_url,$invoker_filter,$filtros_adicionales){
		$url = $base_url;
		$description_string = 'hoteles';
		
		$items_list_string 			= "";
		$additional_filters_string 	= "";
		foreach ($this->filters_list as $current_key => $current_filter){
			if ($current_filter['selected'] && $invoker_filter != $current_filter['field_denomination']){
				switch ($current_filter['filter_type']){
					case 'items_list' : 
						$values = "";
						foreach ($this->filters_list[$current_filter['field_denomination']]['selected_value'] as $value){
							if ($values != ""){
								$values .= '-';
							}
							$values .= str_replace(' ','+',$value);
						}
						$items_list_string .= '/'.$current_filter['field_denomination'].'/' . $values;
					break;
					case 'text' : $additional_filters_string .= '/' . $current_filter['field_denomination'] . '/' . $current_filter['selected_value']; break;
					case 'range' : 
						if (!is_null($current_filter['selected_value']['min']) && !is_null($current_filter['selected_value']['min'])){
							$additional_filters_string .= '/'.$current_filter['field_denomination'].'/' . $current_filter['selected_value']['min'] . '-' . $current_filter['selected_value']['max'];
						}
						else{
							if (!is_null($current_filter['selected_value']['min'])){
								$additional_filters_string .= '/'.$current_filter['field_denomination'].'/' . $current_filter['selected_value']['min'] . '-';
							}
							else{
								$additional_filters_string .= '/'.$current_filter['field_denomination'].'/' . $current_filter['selected_value']['max'] . '+';
							}
						}
					break;
					;
				}
			}
		}
		
		return '/' . $url . $items_list_string . $additional_filters_string . $this->mandatory_filters_string . '/' . $description_string;
	}

	
	function get_display_value($denomination,$value,$display_value,$text){
		global $arrayMeses;
		switch ($denomination){
			case 'periodo' :
				$temp			= explode('_',$value);
				$return_string	= $arrayMeses[$temp[0]-1] . ' ' . $temp[1];
			break;
			case 'puerto' :
				$return_string = str_replace('<value>',ucfirst(strtolower($display_value)),$text);
			break;
			case 'region' :
				$temp = explode('_',$display_value);
				$display_value = $temp[0];
				if ( isset($temp['1']) && $temp['0'] != $temp['1']){
					$display_value .= ' (' . $temp['1'] . ')';
				}
				$return_string = str_replace('<value>',ucfirst(strtolower($display_value)),$text);
			break;
			default:
				$return_string = str_replace('<value>',$display_value,$text);
			break;
		}
		return $return_string;
	}	

}


?>